import API from '../../utils/api'
import common from '../../utils/common'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activityList:[],
    attention:'关注',
    attentionState:0,
    uid:'',
    iscancer:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.minePageData(options.uid)
    this.setData({
      uid:options.uid
    })
  },
  // 关注
  attentionBtn (){
    API.addCancer({masterid:this.data.uid}).then(res=>{
      if (res.code == 0) {
        wx.showToast({
          title: '关注成功',
          icon: 'success',
          duration: 2000
        })
        this.setData({
          attention:'已关注'
        })
        this.minePageData(this.data.uid)
      }
    })
  },
  // 取消关注
  quxiaoCancer () {
    API.quxiaoCancer({masterid:this.data.uid}).then(res=>{
      if (res.code == 0) {
        wx.showToast({
          title: '取消成功',
          icon: 'success',
          duration: 2000
        })
        this.setData({
          attention:'关注'
        })
        this.minePageData(this.data.uid)
      }
    })
  },
  minePageData (uid) {
    
    API.minePage({uid:uid}).then(res=>{
      if (res.code == 0) {
        var active = res.data.active
        for (var k in active) {
          active[k].startime = common.dateFormat(active[k].startime,1)
        }
        this.setData({
          personInfo:res.data.personInfo,
          activeList:active,
          iscancer: res.data.iscancer
        })
      }
    })
  },
  onShow: function () {

  },
  toActivityDetail (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/activityDetail/activityDetail?id=' + id
    })
  }


})